package com.byd.dms.fastjson;


import com.alibaba.fastjson.JSON;
import net.sf.json.JSONObject;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

public class JSON1 {
    
    
    @Test
    public void mapToJson() {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("username", "刘阿勇");
        jsonMap.put("password", "123love");
        
        String contentString = JSONObject.fromObject(jsonMap).toString();
        System.out.println(contentString);
        
        String s = JSON.toJSONString(jsonMap);
        System.out.println(s);
    }
    
    @Test
    public void jsonToObject() {
        String str = "{\"password\":\"123love\",\"username\":\"刘阿勇\"}";
        Map map = JSON.parseObject(str, Map.class);
        System.out.println(map);
        
    }
    
}
